using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Jasongozy.Alaton;
namespace Jasongozy.Alaton.Test.UnitTest {
    [TestFixture]
    public class TypeParseTest {
        [Test]
        public void TestConvertersToInt() {
            string input = "11";
            int res = Converters.ParseStringToValueType<int>(input, 0);
            Assert.AreEqual(11, res);

            string input2 = "1s";
            int res2 = Converters.ParseStringToValueType<int>(input2, 0);
            Assert.AreEqual(0, res2);
        }

        [Test]
        public void TestConvertersComparePreformance() {
            CodeTimer.Initialize();
            string input = "11";
            int res = 0;
            res = Converters.ParseStringToValueType<int>(input, 0);
            res = int.Parse(input);

            CodeTimer.Time<string>("Converters", 100000, delegate(string p) {
                Converters.ParseStringToValueType<int>(input, 0);
            });

            CodeTimer.Time<string>("Converters", 100000, delegate(string p) {
                int.Parse(input);
            });
        }

        [Test]
        public void TestStringParseToValueType() {
            string s1 = "1";
            string s2 = "23123131312313123";
            string s3 = "312323232.55555";
            string s4 = "123";
            string s5 = "True";
            string s6 = "2010-9-22 2:3:11";
            Assert.AreEqual(1, TypeParser.ToInt(s1, 0));
            Assert.AreEqual(0,TypeParser.ToInt(s2,0));
            Assert.AreEqual(23123131312313123L, TypeParser.ToLong(s2, -1L));
            Assert.AreEqual(312323232.55555d, TypeParser.ToDouble(s3, -1d));
            Assert.AreEqual((Int16)123, TypeParser.ToInt16(s4, (Int16)0));
            Assert.AreEqual(true, TypeParser.ToBool(s5, false));
            Assert.AreEqual(new DateTime(2010,9,22,2,3,11), TypeParser.ToDateTime(s6, DateTime.MinValue));
        }
    }
}
